package 剑指offer;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class 剑指Offer03数组中重复的数字 {
    //排序后在查找
    public int findRepeatNumber1(int[] nums) {
        Arrays.sort(nums);
        for (int i = 0; i < nums.length-1; i++) {
            if ((nums[i] ^ nums[i+1]) == 0){
                return nums[i];
            }
        }
        return -1;
    }
    public int findRepeatNumber(int[] nums) {
        //hashSet去重法
        Set<Integer> set = new HashSet<>();
        for (int i:nums) {
            if (set.contains(i)) return i;
            set.add(i);
        }
        return -1;
    }
}
